package reliability.ui;

import javax.swing.*;
import java.awt.event.ActionListener;

public class GraphPanelPopup
    extends JPopupMenu
{
    public static final String ADD_EDGE_COMMAND = "Добавить связь";
    public static final String ADD_NODE_COMMAND = "Добавить узел";
    public static final String DELETE_COMMAND = "Удалить элемент";

    private JMenuItem deleteMenuItem = new JMenuItem(DELETE_COMMAND);
    private JMenuItem addEdgeMenuItem = new JMenuItem(ADD_EDGE_COMMAND);
    private JMenuItem addNodeMenuItem = new JMenuItem(ADD_NODE_COMMAND);
    private GraphPanelPopupType type = GraphPanelPopupType.EMPTY_POPUP;

    public GraphPanelPopup(ActionListener listener)
    {
        super();
        addEdgeMenuItem.addActionListener(listener);
        addNodeMenuItem.addActionListener(listener);
        deleteMenuItem.addActionListener(listener);
    }

    public GraphPanelPopupType getType()
    {
        return type;
    }

    public void updateContext(GraphPanelPopupType type)
    {
        this.type = type;
        removeAll();
        switch (type)
        {
            case NODE_POPUP:
                add(addEdgeMenuItem);
                add(deleteMenuItem);
                break;
            case EDGE_POPUP:
                add(deleteMenuItem);
                break;
            case EMPTY_POPUP:
                add(addNodeMenuItem);
                break;
        }
    }

    public void addAddEdgeActionListener(ActionListener listener)

    {
        addEdgeMenuItem.addActionListener(listener);
    }

    public JMenuItem getDeleteMenuItem()
    {
        return deleteMenuItem;
    }

    public JMenuItem getAddEdgeMenuItem()
    {
        return addEdgeMenuItem;
    }
}
